<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/


namespace News\Model;
use Think\Model;

class ArticleModel extends Model {
	
	function GetList($type=1){
		$pagenum=intval($_GET['p']);
		$type=intval($type);
		
		$name=$route='';
		if(preg_match('/^[a-z]+$/i',$_GET['catid'])){ 
			$route=$_GET['catid'];
			$categoryone= M('Category')->token(false)->where(" route='$route' ")->find();
			if(!empty($categoryone)){
				$catid=$categoryone['catid'];
				$route=$categoryone['route'];
				$name=$categoryone['name'];
				if(!empty($categoryone['nexts'])){
					$categoryid=$categoryone['nexts'];
					$where.=" AND catid IN($categoryid) ";
				}
				$category= M('Category')->token(false)->where(" upid=$catid AND news=1 ")->select();
			}
		}else{
			//1级
			$category= M('Category')->token(false)->where(" upid=0 AND news=1 ")->select();
		}
		
		$wheresql=" type=$type ";
		if($where){
			$wheresql.=$where;
		}
		
		$order='dateline DESC';
		
		//数据-------------------------------
		$list=$this->token(false)->where($wheresql)->order($order)->page($pagenum,20)->select();

		//页码-------------------------------
		$count=$this->token(false)->where($wheresql)->count();
		$Page = new \Think\Page($count,20);
	

		$newpage=str_replace("Index/index/catid/",'',$Page->show());
		$newpage=str_replace("/m/news",'',$newpage);
		
		return array('list'=>$list,'page'=>$newpage,'route'=>$route,'name'=>$name);
	}
}

?>